package com.mall.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.R;
import com.mall.entity.SmoothMallCategory;
import com.mall.entity.SmoothMallUser;
import com.mall.entity.TbSeckillVoucher;
import com.mall.entity.dto.SmoothMallCategoryDto;
import com.mall.mapper.SmoothMallUserMapper;
import com.mall.mapper.TbSeckillVoucherMapper;
import com.mall.service.SmoothMallUserService;
import com.mall.service.TbSeckillVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class TbSeckillVoucherServiceImpl extends ServiceImpl<TbSeckillVoucherMapper, TbSeckillVoucher> implements TbSeckillVoucherService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addSeckillVoucher(TbSeckillVoucher voucher) {
        // 保存秒杀优惠券
        save(voucher);
        // 保存秒杀优惠券信息到Reids，Key名中包含优惠券ID，Value为优惠券的剩余数量
        stringRedisTemplate.opsForValue().set("seckill:stock:" + voucher.getVoucherId(), voucher.getStock().toString());
    }
}
